#
# Created by Administrator on 2021/7/29 AT 8:52.
#
from typing import List


class Solution:
    def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
        """
        Do not return anything, modify nums1 in-place instead.
        """
        # 因为是排在nums1的后面，因此从大到小排
        p1, p2 = m - 1, n - 1
        tail = m + n - 1
        cur = 0
        while p1 >= 0 or p2 >= 0:
            if p1 == -1:
                cur = nums2[p2]
                p2 -= 1
            elif p2 == -1:
                cur = nums1[p1]
                p1 -= 1
            elif nums1[p1] >= nums2[p2]:
                cur = nums1[p1]
                p1 -= 1
            else:
                cur = nums2[p2]
                p2 -= 1
            nums1[tail] = cur
            tail -= 1


if __name__ == '__main__':
    sol = Solution()
    nums1 = [1, 2, 3, 0, 0, 0]
    nums2 = [2, 5, 6]
    sol.merge(nums1, 3, nums2, 3)
    print(nums1)
